<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="作物名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入作物名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['crop:products:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['crop:products:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['crop:products:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cropList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="农作物id"  width="100px" align="center" prop="cropId" />
      <el-table-column label="农作物编码"  width="100px" align="center" prop="cropCode" />
      <el-table-column label="作物名称" align="center" prop="name" />
      <el-table-column label="图片" width="100px"  align="center" prop="img">
        <template slot-scope="scope" >
          <img :src="scope.row.img" alt="" style="width: 100px;height: 100px">
        </template>
      </el-table-column>
      <el-table-column label="农户手机号" align="center" prop="phone" />
      <el-table-column label="每/亩" align="center" prop="mu">
        <template v-slot="s">
          {{s.row.mu}}亩
        </template>
      </el-table-column>
      <el-table-column label="每亩/斤" align="center" prop="axe">
        <template v-slot="s">
          {{s.row.axe}}斤
        </template>
      </el-table-column>
      <el-table-column label="总数" align="center" prop="count"/>
      <el-table-column label="作物类型" align="center" prop="typeId">
        <template v-slot="scope">
          <dict-tag :options="dict.type.sys_crop_type" :value="scope.row.typeId"/>
        </template>
      </el-table-column>
      <el-table-column label="肥料编号" align="center" prop="fertilizerId">
        <template v-slot="scope">
          <dict-tag :options="dict.type.sys_fertilizer" :value="scope.row.fertilizerId"/>
        </template>
      </el-table-column>
      <el-table-column label="种植" align="center" prop="plantId" >
        <template v-slot="scope">
          <dict-tag :options="dict.type.sys_crop_plant" :value="scope.row.plantId"/>
        </template>
      </el-table-column>
      <el-table-column label="种植年度" align="center" prop="plantAge">
        <template v-slot="s">
          {{s.row.plantAge}}年
        </template>
      </el-table-column>
      <el-table-column label="是否套袋" align="center" prop="flat">
        <template v-slot="s">
          <el-button size="mini" type="primary" v-if="s.row.flat==0">是</el-button>
          <el-button size="mini" type="primary" v-if="s.row.flat==1">否</el-button>
        </template>
      </el-table-column>
      <el-table-column label="育苗周期" align="center" prop="seedlingCycle">
        <template v-slot="s">
          {{s.row.seedlingCycle}}周
        </template>
      </el-table-column>
      <el-table-column label="灌溉周期" align="center" prop="irrigationCycle">
        <template v-slot="s">
          {{s.row.irrigationCycle}}周
        </template>
      </el-table-column>
      <el-table-column label="施肥周期" align="center" prop="fertilizationCycle">
        <template v-slot="s">
          {{s.row.fertilizationCycle}}周
        </template>
      </el-table-column>
      <el-table-column label="除草周期" align="center" prop="weedingCycle">
        <template v-slot="s">
          {{s.row.weedingCycle}}周
        </template>
      </el-table-column>
      <el-table-column label="省/市/县"  width="200px" align="center" prop="address" />
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="种植时间" align="center" prop="zzTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zzTime, '{y}-{m}-{d}')}}</span>
        </template>
      </el-table-column>
      <el-table-column label="种植成熟时间" align="center" prop="jsTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jsTime, '{y}-{m}-{d}')}}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template v-slot="s">
          <el-button size="mini" type="success" v-if="s.row.status==0">种植中</el-button>
          <el-button size="mini" type="success" v-if="s.row.status==1">收成完成</el-button>
          <el-button size="mini" type="success" v-if="s.row.status==2">入库</el-button>
          <el-button size="mini" type="success" v-if="s.row.status==3">运输</el-button>
          <el-button size="mini" type="success" v-if="s.row.status==4">不合格退货</el-button>
          <el-button size="mini" type="success" v-if="s.row.status==5">成熟</el-button>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['crop:products:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['crop:products:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.status==5"
            @click="handleSH(scope.row)"
          >收成</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handlezq(scope.row)"
            v-hasPermi="['crop:products:remove']"
          >生长周期</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.status==1"
            @click="handleYunshu(scope.row)"
          >开始检测</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


    <!-- 添加或修改农作物主对话框 -->
    <el-dialog :title="title" :visible.sync="dialogFormVisible">
      <el-form  :model="form" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="作物名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入作物名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="图片" prop="img">
              <el-upload
                class="avatar-uploader"
                action="http://localhost:9222/upload/uploadFile"
                :show-file-list="false"
                :on-success="handleAvatarSuccess">
                <img v-if="imageUrl" :src="imageUrl" style="width: 100px;height: 100px;" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="每/亩" prop="mu">
              <el-input v-model="form.mu" @change="handCount" placeholder="请输入亩" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="每亩/斤" prop="axe">
              <el-input v-model="form.axe" @change="handCount" placeholder="请输入斤" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="手机号" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入农户手机号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预计数量" prop="count">
              <el-input v-model="countValue" placeholder="请输入预计数量" />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="12">
            <el-form-item label="作物类型" prop="typeId">
              <el-select v-model="form.typeId" placeholder="请输入作物类型">
                <el-option
                  v-for="item in dict.type.sys_crop_type"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="肥料类型" prop="fertilizerId">
              <el-select v-model="form.fertilizerId" placeholder="请输入肥料类型">
                <el-option
                  v-for="item in dict.type.sys_fertilizer"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="种植方式" prop="plantId">
              <el-select v-model="form.plantId" placeholder="请输入种植方式">
                <el-option
                  v-for="item in dict.type.sys_crop_plant"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="种植年度" prop="plantAge">
              <el-input v-model="form.plantAge" placeholder="请输入种植年度" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="是否套袋" prop="flat">
              <el-select v-model="form.flat" placeholder="请输入育苗周期">
                <el-option label="是" :value="0">是</el-option>
                <el-option label="否" :value="1">否</el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="育苗周期" prop="seedlingCycle">
              <el-select v-model="form.seedlingCycle" placeholder="请输入育苗周期">
                <el-option label="1" value="1"></el-option>
                <el-option label="2" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="灌溉周期" prop="irrigationCycle">
              <el-select v-model="form.irrigationCycle" placeholder="请输入灌溉周期">
                <el-option label="1" value="1"></el-option>
                <el-option label="2" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="施肥周期" prop="fertilizationCycle">
              <el-select v-model="form.fertilizationCycle" placeholder="请输入施肥周期">
                <el-option label="1" value="1"></el-option>
                <el-option label="2" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="除草周期" prop="weedingCycle">
                <el-select v-model="form.weedingCycle" placeholder="请输入除草周期">
                  <el-option label="1" value="1"></el-option>
                  <el-option label="2" value="2"></el-option>
                </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="省/市/县">
              <el-cascader
                v-model="cityValue"
                :options="options"
                :props="cityProps"
                @change="handleChange"></el-cascader>
            </el-form-item>
          </el-col>
        </el-row>

<!--        <el-row>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="开始时间" prop="beginTime">-->
<!--              <el-date-picker-->
<!--                v-model="timeValue"-->
<!--                :picker-options="pickerOptions"-->
<!--                type="datetimerange"-->
<!--                range-separator="至"-->
<!--                value-format="yyyy-MM-dd HH:mm:ss"-->
<!--                start-placeholder="开始日期"-->
<!--                end-placeholder="结束日期">-->
<!--              </el-date-picker>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->

        <el-row>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input type="textarea" v-model="form.remark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="12">
            <el-form-item label="种植时间" prop="remark">
              <el-date-picker
                v-model="form.zzTime"
                type="date"
                @change="handTime"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="种植结束时间" prop="remark">
              <el-date-picker
                v-model="endValue"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改农作物主对话框 -->

    <el-drawer
      title="孩子成长记录表!"
      :visible.sync="table"
      direction="rtl"
      size="80%">

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleGrowAdd"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
        </el-col>
      </el-row>

      <el-table  :data="growList">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="生长编号" align="center" prop="growId" />
          <el-table-column label="农作物编号" align="center" prop="cropCode" />
          <el-table-column label="温度" align="center" prop="temperature" />
          <el-table-column label="生长情况" align="center" prop="growStatus">
            <template v-slot="scope">
              <dict-tag :options="dict.type.sys_grow_status" :value="scope.row.growStatus"/>
            </template>
          </el-table-column>
          <el-table-column label="水分" align="center" prop="water" />
          <el-table-column label="光照情况" align="center" prop="lightStatus">
            <template v-slot="scope">
              <dict-tag :options="dict.type.sys_light_status" :value="scope.row.lightStatus"/>
            </template>
          </el-table-column>
          <el-table-column label="生长图片" align="center" prop="pic" >
            <template v-slot="s">
              <img :src="s.row.pic" style="width: 100px;height: 100px;">
              </img>
            </template>
          </el-table-column>
          <el-table-column label="记录添加时间" align="center" prop="beginTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.beginTime)}}</span>
            </template>
          </el-table-column>
          <el-table-column label="记录结束时间" align="center" prop="endTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.endTime)}}</span>
            </template>
          </el-table-column>
          <el-table-column label="备注" align="center" prop="remark" />
      </el-table>
    </el-drawer>
    <!-- 添加生长主对话框 -->
    <el-dialog :title="title" :visible.sync="dialog">
      <el-form  :model="growForm" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="农作物编号" prop="cropCode">
              <el-input v-model="cropCode" disabled placeholder="请输入农作物编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="图片" prop="img">
              <el-upload
                class="avatar-uploader"
                action="http://localhost:9222/upload/uploadFile"
                :show-file-list="false"
                :on-success="handleAvatarSuccess">
                <img v-if="imageUrl" :src="imageUrl" style="width: 100px;height: 100px;" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="温度" prop="temperature">
              <el-input v-model="growForm.temperature" placeholder="请输入温度" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="水分" prop="water">
              <el-input v-model="growForm.water" placeholder="请输入水分" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="growForm.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="生长情况" prop="unit">
              <el-select v-model="growForm.growStatus" placeholder="请输入生长情况">
                <el-option
                  v-for="item in dict.type.sys_grow_status"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="光照情况" prop="unit">
              <el-select v-model="growForm.lightStatus" placeholder="请输入光照情况">
                <el-option
                  v-for="item in dict.type.sys_light_status"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="开始时间" prop="beginTime">
              <el-date-picker
                v-model="timeValue"
                :picker-options="pickerOptions"
                type="datetimerange"
                range-separator="至"
                value-format="yyyy-MM-dd HH:mm:ss"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialog = false">取 消</el-button>
        <el-button type="primary" @click="submitGrow">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 结束生长主对话框 -->

    <!-- 开始收货 -->
    <el-dialog :title="title" :visible.sync="dialogFormVisibles" style="width: 1000px;margin-left: 400px">
      <el-form :model="YForm">
        <el-form-item label="实际收获数量">
          <el-input-number v-model="num"  :min="0" :max="9999"></el-input-number>
        </el-form-item>
        </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisibles = false">取 消</el-button>
        <el-button type="primary" @click="submitYF">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 结束收货 -->


    <!-- 开始检测人 -->
    <el-dialog :title="title" :visible.sync="dialogFormVisiblePerson" style="width: 1000px;margin-left: 400px">
      <el-form :model="JianForm">
        <el-row>
          <el-col :span="12">
            <el-form-item label="请选择质检人" v-if="zjName===undefined">
              <el-button
                v-model="toCheckId"
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="openAddCheck(toCheckId)"
              >请选择质检人</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="请选择质检人"  v-if="zjName!==undefined">
              <el-tag  v-model="zjName">{{zjName}}</el-tag>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisiblePerson = false">取 消</el-button>
        <el-button type="primary" @click="submitJian">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 结束检测人 -->

    <!--开始质检列表-->
    <el-dialog :title="title" :visible.sync="dialogFormVisibleCheck">
      <ToChecker :check="check" @close="closeComponent"></ToChecker>
    </el-dialog>
    <!--结束质检列表-->
  </div>
</template>

<script>
import {
  listCrop,
  getCheckList,
  getWarehouseList,
  UpdateYF,
  getCrop,
  delCrop,
  addCrop,
  updateCrop,
  cityTreeSelect,
  getZZtime,
  listGrow,
  addGrow,
  addYunShu,
  getCount,
} from "@/api/crop/products";
import ToChecker from "@/views/crop/products/ToChecker";
import cropIng from "@/store/modules/cropIng";

export default {
  components: {ToChecker},
  name: "index",
  dicts: ['sys_grow_status', 'sys_light_status','sys_crop_type','sys_crop_plant','sys_fertilizer'],
  watch:{
    check:{
      if(check){
        console.log(check,"监听")
      }
    }
  },
  data() {
    return {
      toCheckId:"ToChecker",
      endValue:undefined,
      loading: true,
      dialog: false,
      dialogFormVisibles: false,
      dialogFormVisiblePerson: false,
      dialogFormVisibleCheck: false,
      growCropId:'',
      YForm: {},
      JianForm: {},
      ids: [],
      check: [],
      checkList: [],
      num: 0,
      types: [],
      growList: [],
      fertilizers: [],
      plants: [],
      single: true,
      multiple: true,
      showSearch: true,
      table: false,
      total: 0,
      cropList: [],
      timeValue: [],
      title: "",
      cropCode:'',
      dialogFormVisible: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
      },
      form: {},
      growForm: {},
      pickerOptions:{
        disabledDate(time){
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      imageUrl:'',
      cityValue: [],
      countValue: undefined,
      options: [],
      cityProps:{
        value:"id",
        label:"name",
      },
      openCheckForm:{
        checkId:undefined,
        checkCode: undefined,
      },
      zjName:undefined,
    };
  },
  methods: {
    closeComponent(){
      console.log(cropIng.state.zjId,"成羽欣美女")
      console.log(cropIng.state.zjName,"成羽欣美女")
      this.zjName=cropIng.state.zjName;
      this.dialogFormVisibleCheck=false;
    },
    handTime(){
      let zzTime = this.form.zzTime;
      let seedlingCycle = this.form.seedlingCycle;
      let irrigationCycle = this.form.irrigationCycle;
      let fertilizationCycle = this.form.fertilizationCycle;
      let weedingCycle = this.form.weedingCycle;
      getZZtime(zzTime,seedlingCycle,irrigationCycle,fertilizationCycle,weedingCycle).then(r=>{
        this.endValue=r.msg;
        console.log(this.endValue);
      })
    },
    handCount(){
      let mu = this.form.mu;
      let axe = this.form.axe;
      getCount(mu,axe).then(r=>{
        this.countValue=r.data;
        console.log(this.countValue)
      })
    },
    submitGrow(){
      this.growForm.beginTime=this.timeValue[0];
      this.growForm.endTime=this.timeValue[1];
      addGrow(this.growForm).then(r => {
        this.$modal.msgSuccess("新增成功");
        this.dialog = false;
        this.getList();
      });
    },
    handleGrowAdd(){
      this.title = "添加生长记录";
      this.growForm={};
      this.timeValue=[];
      this.imageUrl=this.growForm.pic;
      this.growForm.cropCode=this.cropCode;
      this.dialog = true;
    },
    getGrowList(cropCode){
      console.log(cropCode);
      listGrow(cropCode).then(r=>{
        this.growList=r.data;
      })
    },
    handlezq(row){
      this.table=true;
      let cropCode = row.cropCode;
      this.cropCode= row.cropCode;
      console.log(this.cropCode+"123123")
      this.getGrowList(cropCode);
    },
    /** 查询城市列表 */
    cityList(){
      cityTreeSelect().then(r=>{
        this.options=r.data;
      })
    },
    /** 查询农作物主列表 */
    getList() {
      this.loading = true;
      listCrop(this.queryParams).then(r => {
        this.cropList = r.rows;
        this.total = r.total;
        this.loading = false;
      });
    },
    handleChange(value) {
      console.log(value);
      if(value!=null&&value.length>0){
        this.form.xid=value[value.length-3];
        this.form.yid=value[value.length-2];
        this.form.zid=value[value.length-1];
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.cropId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.title = "添加农作物";
      this.form={};
      this.cityValue=[];
      // this.timeValue=[];
      this.cityList();
      this.imageUrl=this.form.img;
      this.dialogFormVisible = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.title = "修改农作物";
      this.form={};
      this.cityValue=[];
      // this.timeValue=[];
      this.cityList();
      this.imageUrl=row.img;
      const cropId = row.cropId || this.ids
      getCrop(cropId).then(r => {
        this.form = r.data;
        this.endValue=this.form.jsTime;
        this.countValue=this.form.count;
        this.cityValue.push(this.form.xid+'');
        this.cityValue.push(this.form.yid+'');
        this.cityValue.push(this.form.zid+'');
        // this.timeValue.push(this.form.beginTime);
        // this.timeValue.push(this.form.endTime);
        this.dialogFormVisible = true;
      });
    },
    /** 提交按钮 */
    submitForm() {
      if (this.form.cropId != null) {
        this.form.jsTime=this.endValue;
        this.form.count=this.countValue;
        updateCrop(this.form).then(r => {
          this.$modal.msgSuccess("修改成功");
          this.dialogFormVisible = false;
          this.getList();
        });
      } else {
        this.form.jsTime=this.endValue;
        this.form.count=this.countValue;
        // this.form.beginTime=this.timeValue[0];
        // this.form.endTime=this.timeValue[1];
        addCrop(this.form).then(r => {
          this.$modal.msgSuccess("新增成功");
          this.dialogFormVisible = false;
          this.getList();
        });
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const cropIds = row.cropId || this.ids;
      this.$modal.confirm('是否确认删除农作物编号为"' + cropIds + '"的数据项？').then(function() {
        return delCrop(cropIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
      this.imageUrl=res;
      this.form.img=res;
      // this.growForm.pic=res;
    },
    handleYunshu(row){
      console.log(row,111)
      this.JianForm=row;
      this.getCheck();
      this.dialogFormVisiblePerson=true;
    },
    submitYF(){
      let cropCode = this.YForm.cropCode;
      let num = this.num;
      console.log(num);
      console.log(cropCode);
      UpdateYF(num,cropCode).then(r => {
        this.$modal.msgSuccess("收获成功");
        this.dialogFormVisibles = false;
        this.getList();
      });
    },
    handleSH(row){
      this.YForm={};
      this.YForm=row;
      console.log(this.YForm)
      this.dialogFormVisibles=true;
    },
    getCheck(){
      getCheckList().then(res =>{
        this.checkList = res.data;
      })
    },
    submitJian(){
      console.log(this.JianForm);
      this.JianForm.zjId=cropIng.state.zjId;
      // alert(this.JianForm.zjId)
      addYunShu(this.JianForm).then(r => {
        this.$modal.msgSuccess("检测成功");
        this.dialogFormVisible = false;
        this.$router.push("/quality/Incoming")
      });
    },
    openAddCheck(){
      this.dialogFormVisibleCheck=true;
    },
  },
  created() {
    this.getList();
  },
};
</script>
